package se.liu.oschi129.world.model;

import java.util.Comparator;

import se.liu.oschi129.world.objects.WorldObject;

/**
 * This is a comparator that is used within the World class. It sorts object by their
 * depth and id. The world object with the highest depth and lowest id are placed
 * in front of the other objects.
 * 
 * @author oschi129
 */
public class WorldDepthComparator implements Comparator<WorldObject> {
	
	/** Two elements cannot be equal - use the hash if the depth is equal! */
	public int compare(WorldObject left, WorldObject right) {
		int comparison = right.getDepth() - left.getDepth();
		if (comparison == 0) {
			return left.getId() - right.getId();
		}
		else
			return comparison;
	}

}
